﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Xml.Utility;

namespace Portal.Workflow.Model
{
    public class WorkflowTaskItemCls
    {
        public string Id;
        public string WorkflowActionId
        {
            get
            {
                return Id;
            }
        }
        public string WorkflowDefId;
        public string WorkflowDefName;
        public string EmployeeId;
        public string RecordId;
        public string RecordNote;
        public string Subject;
        public string Description;
        public DateTime ActionDate;
        public string ViewParam;
        public string ComeFromLoginName;
        public string ComeFromFullName;
        public string ProcessType="to";
        public string CurrentProcessUser = "";
        public string CurrentProcessFullName = "";
        public int IsReply = 0;
    }

    public class WorkflowTaskItemParser
    {
        public static WorkflowTaskItemCls CreateInstance()
        {
            //tao 1 class trang....
            WorkflowTaskItemCls oWorkflowTaskItemCls = new WorkflowTaskItemCls();
            return oWorkflowTaskItemCls;
        }

        public static WorkflowTaskItemCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            WorkflowTaskItemCls oWorkflowTaskItemCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oWorkflowTaskItemCls;
        }


        public static WorkflowTaskItemCls ParseFromDataRow(DataRow dr)
        {
            WorkflowTaskItemCls oWorkflowTaskItemCls = new WorkflowTaskItemCls();

            oWorkflowTaskItemCls.Id = XmlUtility.GetString(dr, "Id", true);
            oWorkflowTaskItemCls.WorkflowDefId = XmlUtility.GetString(dr, "WorkflowDefId", true);
            oWorkflowTaskItemCls.WorkflowDefName = XmlUtility.GetString(dr, "WorkflowDefName", true);
            oWorkflowTaskItemCls.EmployeeId = XmlUtility.GetString(dr, "EmployeeId", true);
            oWorkflowTaskItemCls.RecordId = XmlUtility.GetString(dr, "RecordId", true);
            oWorkflowTaskItemCls.RecordNote = XmlUtility.GetString(dr, "RecordNote", true);
            oWorkflowTaskItemCls.Subject = XmlUtility.GetString(dr, "Subject", true);
            oWorkflowTaskItemCls.Description = XmlUtility.GetString(dr, "Description", true);
            oWorkflowTaskItemCls.ActionDate = (DateTime)dr["ActionDate"];
            oWorkflowTaskItemCls.ViewParam = XmlUtility.GetString(dr, "ViewParam", true);
            oWorkflowTaskItemCls.ComeFromLoginName = XmlUtility.GetString(dr, "ComeFrom", true);
            oWorkflowTaskItemCls.ComeFromFullName = XmlUtility.GetString(dr, "ComeFromName", true);
            oWorkflowTaskItemCls.ProcessType = XmlUtility.GetString(dr, "ProcessType", true);
            oWorkflowTaskItemCls.CurrentProcessUser = XmlUtility.GetString(dr, "CurrentProcessUser", true);
            oWorkflowTaskItemCls.CurrentProcessFullName = XmlUtility.GetString(dr, "CurrentProcessFullName", true);
            oWorkflowTaskItemCls.IsReply = XmlUtility.GetInt(dr, "IsReply", true);

            return oWorkflowTaskItemCls;
        }

        public static WorkflowTaskItemCls[] ParseFromDataTable(DataTable dtTable)
        {
            WorkflowTaskItemCls[] SMSItems = new WorkflowTaskItemCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                SMSItems[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return SMSItems;
        }

        public static WorkflowTaskItemCls[] ParseMultiRecordFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            if (ds.Tables.Count == 0)
            {
                return new WorkflowTaskItemCls[0];
            }
            WorkflowTaskItemCls[] SMSItems = new WorkflowTaskItemCls[ds.Tables[0].Rows.Count];
            for (int iIndex = 0; iIndex < ds.Tables[0].Rows.Count; iIndex++)
            {
                SMSItems[iIndex] = ParseFromDataRow(ds.Tables[0].Rows[iIndex]);
            }
            return SMSItems;
        }
    }
}

